#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#include <SDL.h>

int main ( int argc, char** argv )
{
    // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }

    // make sure SDL cleans up before exit
    atexit(SDL_Quit);

    // create a new window
    SDL_Surface* screen = SDL_SetVideoMode(978, 601, 32,
                                           SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
    if ( !screen )
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }

    // load an image
    SDL_Surface* mp = SDL_LoadBMP("img/1.bmp");


    if (!mp)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }
    SDL_Surface *mg = SDL_LoadBMP("img/fleche.bmp");
if (mg == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}

    // centre the bitmap on screen
    SDL_Rect dct;
    dct.x = 200 ;
    dct.y =  80;

    // program main loop
      bool done = false;
    SDL_EnableKeyRepeat(1,1);
    SDL_SetColorKey(mg,SDL_SRCCOLORKEY,SDL_MapRGB(mg->format,255,255,255));

    while (!done)
    {
        // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = true;
                break;

                // check for keypresses
            case SDL_KEYDOWN:
                {
                    // exit if ESCAPE is pressed
                    switch (event.key.keysym.sym)
                    {

                     case  SDLK_ESCAPE:
                     done = true;
                    break;
                     case SDLK_UP:
                         if(dct.y==250)
                        dct.y=dct.y-170;

                        break;
                    case SDLK_DOWN:
                        if(dct.y==80)
                        dct.y= dct.y+170;
                        break;
                    case SDLK_SPACE:
                     if (dct.y==250)
                        done= true ;
                    if (dct.y==80)
                    {


                     // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }
    // make sure SDL cleans up before exit
    atexit(SDL_Quit);
    // create a new window
    SDL_Surface* screen = SDL_SetVideoMode(978, 601, 32,
                                           SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
    if ( !screen )
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }
    // load an image
    SDL_Surface* bmp = SDL_LoadBMP("img/image.bmp");
    if (!bmp)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }
    SDL_Surface *image = SDL_LoadBMP("img/mario.bmp");
if (image == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
    // centre the bitmap on screen
    SDL_Rect dstrect;
    dstrect.x = 80;
    dstrect.y =  0;

    // program main loop
      bool done = false;
    SDL_EnableKeyRepeat(100,10);
    SDL_SetColorKey(image,SDL_SRCCOLORKEY,SDL_MapRGB(image->format,255,255,255));
    while (!done)
    {
        // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = true;
                break;
                // check for keypresses
            case SDL_KEYDOWN:
                {
                    // exit if ESCAPE is pressed
                    switch (event.key.keysym.sym)
                    {
                     case  SDLK_ESCAPE:
                     done = true;
                    break;
                     case SDLK_SPACE:
                       dstrect.y=dstrect.y-310;
                        break;
                    case SDLK_RIGHT:
                        dstrect.x++;
                        break;
                        case SDLK_LEFT:
                        dstrect.x--;
                        break;
            }
             case SDL_KEYUP:
                {
                 switch (event.key.keysym.sym)
                  case SDLK_SPACE:
                       dstrect.y=dstrect.y+155;
                        break;
                } }}break; // end switch
        } // end of message processing
        // DRAWING STARTS HERE
        // clear screen
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
        // draw bitmap
        SDL_BlitSurface(bmp, NULL, screen, NULL);
        SDL_BlitSurface(image, NULL, screen, &dstrect);
        // DRAWING ENDS HERE
        // finally, update the screen
        SDL_Flip(screen);
    } // end main loop
    // free loaded bitmap
    SDL_FreeSurface(bmp);
 SDL_FreeSurface(image);
    // all is well
    printf("Exited cleanly\n");
    return 0;

}

                        break;




            }}}break; // end switch
        } // end of message processing


        // DRAWING STARTS HERE

        // clear screen
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

        // draw bitmap
        SDL_BlitSurface(mp, NULL, screen, NULL);
        SDL_BlitSurface(mg, NULL, screen, &dct);

        // DRAWING ENDS HERE

        // finally, update the screen :)
        SDL_Flip(screen);
    } // end main loop

    // free loaded bitmap
    SDL_FreeSurface(mp);
 SDL_FreeSurface(mg);
    // all is well ;)
    printf("Exited cleanly\n");

    return 0;

}

